<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <!-- 满足有些用户在手机端访问的需要 -->

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">

    <title>用户管理</title>
    <!-- 线上环境 -->
    <link rel="stylesheet" href="/static/css/dist/component-min.css">
    <link rel="stylesheet" href="/static/plugins/jbox/jbox-min.css">

    <!--vue-->
    <script src="/static/vue/vue.js"></script>
    <!--element ui-->
    <script src="/static/element/index.js"></script>
    <link rel="stylesheet" href="/static/element/index.css">
    <style>
        .el-table__empty-block {
            height: 0;
        }
        .img-delete:before {
            position: absolute;
            top: -5px;
            color: red;
            margin-left: -15px;
            z-index: 999;
        }
    </style>

</head>
<body class="cp-bodybox">
<div id="app">
    <#include "/common/header-fg.html" />

    <div class="container">
        <div class="inner clearfix">
            <#include "/common/left-menu-fg.html" />

            <div class="content-right">
                <h1 class="content-right-title" v-if="readonly">商家详情</h1>
                <h1 class="content-right-title" v-else>编辑商家</h1>
                <el-tabs v-model="activeName" type="border-card">
                    <el-tab-pane label="基本信息" name="first">
                        <el-form :inline="true" ref="baseInfo" :model="baseInfo" :rules="rules" label-width="120px">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="上级商家">
                                        <el-input v-model="parentName" disabled></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="名称" prop="name">
                                        <el-input v-model="baseInfo.name" :disabled="readonly"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item label="状态">
                                        <el-select v-model="baseInfo.status" placeholder="请选择状态" disabled>
                                            <el-option
                                                    v-for="item in stateList"
                                                    :label="item.label"
                                                    :value="item.value">
                                            </el-option>
                                        </el-select>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item label="地址" prop="city">
                                        <el-cascader
                                                :disabled="readonly"
                                                v-model="baseInfo.city"
                                                v-loading="addressLoading"
                                                :options="addressList"
                                                @active-item-change="handleItemChange"
                                        ></el-cascader>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item label="详细地址" prop="address">
                                        <el-input type="textarea" v-model="baseInfo.address" style="width: 300px" :disabled="readonly"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="邮政编码" prop="zipCode">
                                        <el-input v-model="baseInfo.zipCode" :disabled="readonly"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="传真号码" prop="fax">
                                        <el-input v-model="baseInfo.fax" :disabled="readonly"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="联系人" prop="linkName">
                                        <el-input v-model="baseInfo.linkName" :disabled="readonly"></el-input>
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="联系电话" prop="linkTel">
                                        <el-input v-model="baseInfo.linkTel" :disabled="readonly"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="电子邮箱" prop="email">
                                        <el-input v-model="baseInfo.email" :disabled="readonly"></el-input>
                                    </el-form-item>
                                </el-col>
                            </el-row>
                        </el-form>
                    </el-tab-pane>
                    <el-tab-pane label="营业信息" name="second">
                        <el-card class="box-card">
                            <el-form :inline="true" ref="extend" :model="extend" :rules="extendRules" label-width="120px">
                                <el-row>
                                    <!--<el-col :span="12">-->
                                        <!--<el-form-item label="企业性质">-->
                                            <!--<el-select v-model="extend.character" :disabled="readonly" placeholder="请选择性质">-->
                                                <!--<el-option-->
                                                        <!--v-for="item in natureList"-->
                                                        <!--:label="item.label"-->
                                                        <!--:value="item.value">-->
                                                <!--</el-option>-->
                                            <!--</el-select>-->
                                        <!--</el-form-item>-->
                                    <!--</el-col>-->
                                    <el-col :span="8">
                                        <el-form-item label="创立时间">
                                            <el-date-picker
                                                    v-model="extend.establishTime" :disabled="readonly"
                                                    type="date"
                                                    placeholder="选择日期">
                                            </el-date-picker>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item label="执照号码" prop="licenseCode">
                                            <el-input v-model="extend.licenseCode" :disabled="readonly"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="8">
                                        <el-form-item label="员工数">
                                            <el-input v-model="extend.staffNumber" :disabled="readonly"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="经营范围">
                                            <el-input type="textarea" v-model="extend.businessScope" style="width: 300px" :disabled="readonly"></el-input>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="执照图片">
                                            <img v-if="extend.licensePicUrl !== ''" :src="qiniuUrl + extend.licensePicUrl" height="100">
                                            <i class="el-icon-circle-close img-delete" v-if="extend.licensePicUrl !== '' && !readonly" @click="deleteImg">
                                            </i>
                                            <el-upload
                                                    style="display: inline-block"
                                                    action="/file/upload"
                                                    :before-upload="beforeUpload"
                                                    :on-success="uploadSuccess"
                                                    :show-file-list="false">
                                                <el-button type="primary" :disabled="readonly" v-if="readonly != true" @click="loading = true"> 上传图片</el-button>
                                                <div slot="tip" class="el-upload__tip" v-if="readonly != true">只能上传jpg/png文件，且不超过500kb</div>
                                            </el-upload>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-card>
                        <el-card class="box-card" style="margin-top: 10px">
                            <el-form :inline="true" ref="extend1" :rules="extendRules"  :model="extend" label-width="120px">
                                <el-row>
                                    <el-col :span="24">
                                        <el-form-item label="积分比例" prop="pointProportion">
                                            <el-row>
                                                <el-col :span="10">
                                                    <el-input v-model.number="extend.pointProportion" :disabled="readonly"></el-input>
                                                </el-col>
                                                <el-col :span="1">
                                                    <span style="margin-left: 10px">%</span>
                                                </el-col>
                                            </el-row>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                        </el-card>
                    </el-tab-pane>
                    <el-tab-pane label="联系人" name="third">
                        <el-card class="box-card">
                            <div style="margin-bottom: 10px" v-if="isPermission('org:addLink', user.permissions)">
                                <el-button type="primary" @click="addLink" :disabled="readonly">添加</el-button>
                            </div>
                            <el-table
                                    :data="linkList"
                                    border
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        label="序号"
                                        width="80">
                                </el-table-column>
                                <el-table-column
                                        prop="name"
                                        label="姓名"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="typeName"
                                        label="类型">
                                </el-table-column>
                                <el-table-column
                                        prop="tel"
                                        label="电话">
                                </el-table-column>
                                <el-table-column
                                        prop="qq"
                                        label="qq">
                                </el-table-column>
                                <el-table-column
                                        prop="email"
                                        label="电子邮箱">
                                </el-table-column>
                                <el-table-column
                                        align="center"
                                        label="操作"
                                        inline-template>
                                    <div style="margin-left: -10px" v-if="isPermission('org:deleteLink', user.permissions)">
                                        <el-button size="small" type="primary" class="el-icon-delete" :disabled="readonly" @click.native.prevent="confirmDeleteLink(row.id)"></el-button>
                                    </div>
                                </el-table-column>
                            </el-table>
                        </el-card>
                    </el-tab-pane>
                    <el-tab-pane label="账号信息" name="fourth">
                        <el-card class="box-card">
                            <div style="margin-bottom: 10px" v-if="isPermission('user:add', user.permissions)">
                                <el-button type="primary" @click="addAccount" :disabled="readonly">添加</el-button>
                            </div>
                            <el-table
                                    :data="accountList"
                                    border
                                    style="width: 100%">
                                <el-table-column
                                        type="index"
                                        label="序号"
                                        width="80">
                                </el-table-column>
                                <el-table-column
                                        prop="realName"
                                        label="姓名"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="enabled"
                                        :formatter="formatEnabled"
                                        label="状态"
                                        width="180">
                                </el-table-column>
                                <el-table-column
                                        prop="tel"
                                        label="电话">
                                </el-table-column>
                                <el-table-column
                                        prop="qq"
                                        label="qq">
                                </el-table-column>
                                <el-table-column
                                        prop="email"
                                        label="电子邮箱">
                                </el-table-column>
                                <el-table-column
                                        prop="regTime"
                                        :formatter="formatRegTime"
                                        label="创建时间">
                                </el-table-column>
                                <el-table-column
                                        align="center"
                                        label="操作"
                                        inline-template>
                                    <div style="margin-left: -10px">
                                        <el-dropdown>
                                            <el-button size="small" type="primary" :disabled="readonly">
                                                操作<i class="el-icon-caret-bottom el-icon--right"></i>
                                            </el-button>
                                            <el-dropdown-menu slot="dropdown" align="center">
                                                <el-dropdown-item v-if="isPermission('user:enable', user.permissions)">
                                                    <el-button size="mini" type="primary" v-if="row.enabled === 1" @click.native.prevent="disable(row)">禁用</el-button>
                                                    <el-button size="mini" type="primary" v-else @click.native.prevent="enable(row)">启用</el-button>
                                                </el-dropdown-item>
                                                <el-dropdown-item v-if="isPermission('user:reset', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="resetPassword(row.id)">重置密码</el-button></el-dropdown-item>
                                                <el-dropdown-item v-if="isPermission('org:deleteAccount', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="confirmDelete(row.id)">删除</el-button></el-dropdown-item>
                                            </el-dropdown-menu>
                                        </el-dropdown>
                                    </div>
                                </el-table-column>
                            </el-table>
                        </el-card>
                    </el-tab-pane>
                </el-tabs>
                <div v-if="!readonly && activeName !== 'third' && activeName !== 'fourth'" style="margin-top: 10px;text-align: center">
                    <el-button type="primary" @click.native.prevent="saveEdit">保存</el-button>
                    <el-button>取消</el-button>
                </div>
                <el-dialog :title="linkTitle" v-model="linkDialog" size="tiny">
                    <el-form :model="contactForm" :rules="linkRules" ref="contactForm" label-width="80px">
                        <el-form-item label="类型" prop="type">
                            <el-select v-model="contactForm.type" placeholder="请选择">
                                <el-option
                                        v-for="item in linkTypeList"
                                        :label="item.name"
                                        :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="姓名" prop="name">
                            <el-input v-model="contactForm.name" style="width: 200px"></el-input>
                        </el-form-item>
                        <el-form-item label="电话" prop="tel">
                            <el-input v-model="contactForm.tel" style="width: 200px"></el-input>
                        </el-form-item>
                        <el-form-item label="qq">
                            <el-input v-model="contactForm.qq" style="width: 200px"></el-input>
                        </el-form-item>
                        <el-form-item label="电子邮箱">
                            <el-input v-model="contactForm.email" style="width: 200px"></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="cancelLink">取 消</el-button>
                        <el-button type="primary" @click="saveLink">确 定</el-button>
                    </div>
                </el-dialog>
                <el-dialog :title="accountTitle" v-model="accountDialog" size="tiny">
                    <el-form :model="accountForm" :rules="accountRules" ref="accountForm" label-width="80px">
                        <el-form-item label="状态" prop="enabled">
                            <el-select v-model="accountForm.enabled" placeholder="请选择状态">
                                <el-option label="禁用" :value="0"></el-option>
                                <el-option label="启用" :value="1"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="姓名" prop="realName">
                            <el-input v-model="accountForm.realName" style="width: 200px"></el-input>
                        </el-form-item>
                        <el-form-item label="电话" prop="tel">
                            <el-input v-model="accountForm.tel" style="width: 200px"></el-input>
                        </el-form-item>
                        <el-form-item label="qq">
                            <el-input v-model="accountForm.qq" style="width: 200px"></el-input>
                        </el-form-item>
                        <el-form-item label="电子邮箱">
                            <el-input v-model="accountForm.email" style="width: 200px"></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="cancelAccount">取 消</el-button>
                        <el-button type="primary" @click="saveAccount">确 定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- end content-right -->

            <a href="javascript:;" class="btn-leftMenuFold" id="j-btn-leftMenuFold"></a>
        </div>
    </div>
    <!-- end container -->

    <!--gonggao-->

    <!--tip-->
    <div class="footer">© 2017 , Inc. All rights reserved.</div>
    <!-- end footer -->
    <div class="fixedBar" style="right: -78px;">
        <ul>
            <template v-for="(item, index) in leftMenuList">
                <li v-if="index==0" :class="'shopManager' + index + ' cur'"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
                <li v-else :class="'shopManager' + index"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
            </template>
        </ul>
        <a href="javascript:;" class="fixedBar-btn" id="j-fixedBar-btn"></a>
    </div>
    <a href="#" id="j-gotop" class="gotop" title="回到顶部" style="left: 1920.59px;"></a>

</div>
<script src="/static/js/dist/lib-min.js"></script>
<script src="/static/js/dist/list.js"></script>
<script src="/static/js/dist/component-min.js"></script>

<!-- 引入api -->
<script src="/static/js/api.js"></script>
<script>
    new Vue({
        el: '#app',
        data: function(){
            return {
                user: ${(user)!'null'},
                activeName: 'first',
                parentName: '',
                form2: {},
                accountTitle: '添加账号',
                accountDialog: false,
                addressLoading: false,
                qiniuUrl: list.qiniuUrl,
                addressList: [],
                linkTitle: '添加联系人',
                linkTypeList: [],
                contactForm: {},
                accountForm: {},
                extendRules: {
                    licenseCode: [
                        {required: true, message: "执照号码不能为空"}
                    ],
                    pointProportion: [
                        {required: true, message: "积分比例不能为空"},
                        {type: "number", message: '积分比例必须为数字'}
                    ]
                },
                linkRules: {
                    type: [
                        {required: true, message: "请选择类型"}
                    ],
                    name: [
                        {required: true, message: "姓名不能为空"}
                    ],
                    tel: [
                        {required: true, message: "电话不能为空"}
                    ]
                },
                accountRules: {
                    enabled: [
                        {required: true, message: "请选择状态"}
                    ],
                    realName: [
                        {required: true, message: "姓名不能为空"}
                    ],
                    tel: [
                        {required: true, message: "电话不能为空"}
                    ]
                },
                rules: {
                    name: [
                        {required: true, message: "商家名称不能为空"}
                    ],
                    city: [
                        {required: true, message: "请选择地址"}
                    ],
                    address: [
                        {required: true, message: "详细地址不能为空"}
                    ],
                    linkName: [
                        {required: true, message: "联系人不能为空"}
                    ],
                    linkTel: [
                        {required: true, message: "联系电话不能为空"},
                        {type: "string", pattern: /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/, message: '请输入合法的电话号码'}
                    ],
                    zipCode: [
                        {type: "string", pattern: /^[1-9]\d{5}(?!\d)$/, message: '请输入合法的邮编'}
                    ],
                    fax: [
                        {type: "string", pattern: /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/, message: '请输入合法的传真号码'}
                    ],
                    email: [
                        {type: "string", pattern: /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, message: '请输入合法的邮箱'}
                    ]
                },
                baseInfo: {
                    address: '',
                    city: [],
                    email: '',
                    fax: '',
                    id: '',
                    linkName: '',
                    linkTel: '',
                    name: '',
                    pid: '',
                    status: '',
                    zipCode: ''
                },
                extend: {
                    character: '',
                    establishTime: '',
                    businessScope: '',
                    id: '',
                    licenseCode: '',
                    licensePicUrl: '',
                    orgId: '',
                    saleAmount: '',
                    saleCount: '',
                    staffNumber: '',
                    pointProportion: ''
                },
                readonly: ${readonly},
                baseInfoData: ${baseInfo},
                extendData: ${extend},
                linkList: ${(linkList)![]},
                accountList: ${(accountList)![]},
                addAccountFlag: ${(addAccountFlag)!false},
                linkDialog: false,
                getProvince: false,
                getCity: false,
                loading: false,
                stateList: [
                    {
                        label: '启用',
                        value: 1
                    },
                    {
                        label: '禁用',
                        value: 0
                    }
                ],
                headerNavList: list.headerNavList,
                accountNavList: list.accountNavList,
                leftMenuList: list.menu
            }
        },
        watch: {
            getProvince: function (val, oldVal) {
                if (val) {
                    this.getAddress(this.baseInfoData.city.substring(0, 2), "city");
                }
            },
            getCity: function (val, oldVal) {
                if (val) {
                    this.getAddress([this.baseInfoData.city.substring(0, 2), this.baseInfoData.city.substring(0, 4)], "area");
                }
            }
        },
        methods: {
            formatEnabled (row, column) {
                let enabled = row.enabled;
                if (enabled === 0) {
                    return "禁用";
                } else {
                    return "启用";
                }
            },
            disable (row) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/user/disable", {id: row.id, enabled: 0}, function (res) {
                    if (res.status === 200) {
                        row.enabled = 0;
                        loading.close();
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('服务器错误', '提示', {
                        confirmButtonText: '确定'
                    });
                })
            },
            enable (row) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/user/enable", {id: row.id, enabled: 1}, function (res) {
                    if (res.status === 200) {
                        row.enabled = 1;
                        loading.close();
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('服务器错误', '提示', {
                        confirmButtonText: '确定'
                    });
                })
            },
            confirmDelete(id){
                let that = this;
                this.$confirm('此操作将永久删除该账号, 是否继续?', '提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(function () {
                    that.deleteAccount(id);
                }).catch(function () {
                    that.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                })
            },
            formatRegTime (row, column) {
                let time = row.regTime;
                if (time !== undefined && time !== null && time.length >= 10) {
                    return time.substring(0, 10);
                } else {
                    return time;
                }
            },
            resetPassword (id) {
                let that = this;
                this.$confirm('此操作将重置密码为初始密码, 是否继续?', '提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(function () {
                    that.resetPwd(id)
                }).catch(function () {
                    that.$message({
                        type: 'info',
                        message: '已取消重置'
                    });
                })
            },
            resetPwd (id) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/user/resettingPwd", {id: id}, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.$alert('重置密码成功', '提示', {
                            confirmButtonText: '确定'
                        });
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('服务器错误', '提示', {
                        confirmButtonText: '确定'
                    });
                })
            },
            deleteAccount (id) {
                let that = this;
                this.http("/user/delete", {id: id}, function (res) {
                    if (res.status === 200) {
                        that.$alert('删除成功', '提示', {
                            confirmButtonText: '确定'
                        });
                        that.getAccountList();
                    } else {
                        that.$alert('删除失败', '提示', {
                            confirmButtonText: '确定'
                        });
                    }
                }, function (res) {
                    that.$alert('删除失败', '提示', {
                        confirmButtonText: '确定'
                    });
                })
            },
            beforeUpload (file) {
                if (file.type === "image/png") {
                    this.imgType = ".png";
                    this.loading = true;
                    return true;
                } else if (file.type === "image/jpeg") {
                    this.imgType = ".jpg";
                    this.loading = true;
                    return true;
                } else {
                    this.$message.error('上传头像图片只能是 JPG 或 png 格式!');
                    return false;
                }
            },
            uploadSuccess(response,file){
                if (response.status === 100) {
                    this.loading = false;
                    this.extend.licensePicUrl = response.returnValue[0].id + this.imgType;
                } else {
                    this.$alert('上传失败', '提示', {
                        confirmButtonText: '确定',
                    });
                }
            },
            deleteImg () {
                this.extend.licensePicUrl = "";
            },
            getOrgLink () {
                let that = this;
                this.$get("/dictionary/list/SEC_ORG_LINK", {}, function (res) {
                    if (res.status === 100) {
                        that.linkTypeList = res.returnValue;
                    } else {
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            saveEdit () {
                let that = this;
                let isViald1 = true;
                let isViald2 = true;
                let isViald3 = true;
                this.$refs.baseInfo.validate(function (valid) {
                    if (!valid) {
                        isViald1 = false;
                    }
                })
                this.$refs.extend.validate(function (valid) {
                    if (!valid) {
                        isViald2 = false;
                    }
                })
                this.$refs.extend1.validate(function (valid) {
                    if (!valid) {
                        isViald3 = false;
                    }
                })
                let loading = '';
                let obj = {
                    address: this.baseInfo.address,
                    city: this.baseInfo.city.length == 3 ? this.baseInfo.city[2] : "",
                    email: this.baseInfo.email,
                    fax: this.baseInfo.fax,
                    id: this.baseInfo.id,
                    linkName: this.baseInfo.linkName,
                    linkTel: this.baseInfo.linkTel,
                    name: this.baseInfo.name,
                    pid: this.baseInfo.pid,
                    status: this.baseInfo.status,
                    zipCode: this.baseInfo.zipCode
                }
                if (this.activeName === 'first') {
                    if (isViald1) {
                        loading = this.$loading({fullscreen: true, lock: true, text: '保存中'});
                        this.http("/org/update", obj, function (res) {
                            if (res.status === 200) {
                                loading.close();
                                that.$alert('保存基本信息成功', '提示', {
                                    confirmButtonText: '确定',
                                });
                            } else {
                                loading.close();
                                that.$alert(res.errMsg, '提示', {
                                    confirmButtonText: '确定',
                                });
                            }
                        }, function (res) {
                            loading.close();
                            that.$alert('保存基本信息失败', '提示', {
                                confirmButtonText: '确定',
                            });
                        })
                    } else {
                        that.$message.error('请完善基本信息');
                    }
                } else if (this.activeName === "second") {
                    if (isViald2 && isViald3) {
                        loading = this.$loading({fullscreen: true, lock: true, text: '保存中'});
                        if (this.extend.establishTime !== "") {
                            let time = this.formatTime(this.extend.establishTime, true);
                            this.extend.establishTime = time;
                        }
                        this.http("/org/extend/update", this.extend, function (res) {
                            if (res.status === 200) {
                                loading.close();
                                that.$alert('保存营业信息成功', '提示', {
                                    confirmButtonText: '确定',
                                });
                            } else {
                                loading.close();
                                that.$alert(res.errMsg, '提示', {
                                    confirmButtonText: '确定',
                                });
                            }
                        }, function (res) {
                            loading.close();
                            that.$alert('保存营业信息失败', '提示', {
                                confirmButtonText: '确定',
                            });
                        })
                    } else {
                        that.$message.error('请完善营业信息');
                    }
                }
            },
            handleItemChange (val) {
                if (val.length === 1) {
                    this.getAddress(parseInt(val[0]), "city");
                } else if (val.length === 2){
                    this.getAddress(val, "area");
                }
            },
            getAddress (code, index) {
                let that = this;
                let cityCode = '';
                if (index === "area") {
                    cityCode = code[1];
                } else {
                    cityCode = code;
                }
                this.addressLoading = true;
                this.http("/city/list", {cityCode: cityCode}, function (res) {
                    if (res.status === 200) {
                        if (index === "province") {
                            that.addressList = res.data.list;
                            that.getProvince = true;
                        } else if (index === "city") {
                            that.addressList.forEach(function (item) {
                                if (item.value === (code+'')) {
                                    item.children = res.data.list;
                                }
                            })
                            that.getCity = true;
                        } else if (index === "area") {
                            for(let i = 0; i < that.addressList.length; i++) {
                                if (that.addressList[i].value === code[0]) {
                                    let data = that.addressList[i].children;
                                    for (let j = 0; j < data.length; j++) {
                                        if (data[j].value === code[1]) {
                                            data[j].children = res.data.list;
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        that.addressLoading = false;
                    } else {
                        that.addressLoading = false;
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    that.addressLoading = false;
                    that.$alert('获取地址数据失败', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            },
            addLink () {
                this.contactForm = {
                    orgId: this.baseInfo.id,
                    type: '',
                    name: '',
                    tel: '',
                    qq: '',
                    email: ''
                }
                this.linkTitle = "添加联系人";
                this.linkDialog = true;
            },
            addAccount () {
                this.accountForm = {
                    orgId: this.baseInfo.id,
                    enabled: '',
                    realName: '',
                    tel: '',
                    qq: '',
                    email: ''
                }
                this.accountTitle = "添加账号";
                this.accountDialog = true;
            },
            confirmDeleteLink (id) {
                let that = this;
                this.$confirm('此操作将永久删除该联系人, 是否继续?', '提示',{
                    confirmButtonText:'确定',
                    cancelButtonText:'取消',
                    type:'warning'
                }).then(function () {
                    that.deleteLink(id)
                }).catch(function () {
                    that.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                })
            },
            deleteLink (id) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true, text: '保存中'});
                this.http("/org/link/delete", {id: id}, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.$alert('删除成功', '提示', {
                            confirmButtonText: '确定',
                            callback: function () {
                                that.getLinkList();
                            }
                        });
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('删除失败', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            },
            cancelLink () {
                this.$refs.contactForm.resetFields();
                this.linkDialog = false;
            },
            saveLink () {
                let that = this;
                let isVaild = true;
                this.$refs.contactForm.validate(function (valid) {
                    if (!valid) {
                        isVaild = false;
                    }
                })
                if (isVaild) {
                    let loading = this.$loading({fullscreen: true, lock: true, text: '保存中'});
                    this.http("/org/link/add", this.contactForm, function (res) {
                        if (res.status === 200) {
                            loading.close();
                            that.$refs.contactForm.resetFields();
                            that.linkDialog = false;
                            that.$alert('保存联系人成功', '提示', {
                                confirmButtonText: '确定',
                                callback: function () {
                                    that.getLinkList();
                                }
                            });
                        } else {
                            loading.close();
                            that.$alert(res.errMsg, '提示', {
                                confirmButtonText: '确定',
                            });
                        }
                    }, function (res) {
                        loading.close();
                        that.$alert('保存联系人失败', '提示', {
                            confirmButtonText: '确定',
                        });
                    })
                } else {
                    that.$message.error('请完善信息');
                }
            },
            getLinkList () {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/org/link/list", {orgId: this.baseInfo.id}, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.linkList = res.data.orgLinkList;
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('获取数据失败', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            },
            cancelAccount () {
                this.$refs.accountForm.resetFields();
                this.accountDialog = false;
            },
            saveAccount () {
                let that = this;
                let isVaild = true;
                this.$refs.accountForm.validate(function (valid) {
                    if (!valid) {
                        isVaild = false;
                    }
                })
                if (isVaild) {
                    let loading = this.$loading({fullscreen: true, lock: true});
                    this.http("/org/account/add", this.accountForm,function (res) {
                        if (res.status === 200) {
                            loading.close();
                            that.$refs.accountForm.resetFields();
                            that.accountDialog = false;
                            that.$alert('添加成功', '提示', {
                                confirmButtonText: '确定',
                                callback: function () {
                                    that.getAccountList();
                                }
                            });
                        } else {
                            loading.close();
                            that.$alert(res.errMsg, '提示', {
                                confirmButtonText: '确定',
                            });
                        }
                    }, function (res) {
                        loading.close();
                        that.$alert('添加失败', '提示', {
                            confirmButtonText: '确定',
                        });
                    })
                } else {
                    that.$message.error('请完善信息');
                }
            },
            getAccountList () {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/org/account/list", {orgId: this.baseInfo.id}, function (res) {
                    if (res.status === 200) {
                        loading.close();
                        that.accountList = res.data.list;
                    } else {
                        loading.close();
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('获取数据失败', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            }
        },
        mounted: function () {
            this.getAddress(0, "province");
            this.getOrgLink();
            if (this.addAccountFlag) {
                this.activeName = "fourth";
            }
            this.parentName = this.baseInfoData.parentName !== undefined ? this.baseInfoData.parentName : '';
            this.baseInfo = {
                address: this.baseInfoData.address !== undefined ? this.baseInfoData.address : '',
                email: this.baseInfoData.email !== undefined ? this.baseInfoData.email : '',
                fax: this.baseInfoData.fax !== undefined ? this.baseInfoData.fax : '',
                id: this.baseInfoData.id !== undefined ? this.baseInfoData.id : '',
                linkName: this.baseInfoData.linkName !== undefined ? this.baseInfoData.linkName : '',
                linkTel: this.baseInfoData.linkTel !== undefined ? this.baseInfoData.linkTel : '',
                name: this.baseInfoData.name !== undefined ? this.baseInfoData.name : '',
                pid: this.baseInfoData.pid !== undefined ? this.baseInfoData.pid : '',
                status: this.baseInfoData.status !== undefined ? this.baseInfoData.status : '',
                zipCode: this.baseInfoData.zipCode !== undefined ? this.baseInfoData.zipCode : ''
            }
            if (this.baseInfoData.city !== undefined) {
                let city = [];
                city.push(this.baseInfoData.city.substring(0, 2));
                city.push(this.baseInfoData.city.substring(0, 4));
                city.push(this.baseInfoData.city);
                this.baseInfo.city = city;
            }
            this.extend = {
                character: this.extendData.character !== undefined ? this.extendData.character : '',
                establishTime: this.extendData.establishTime !== undefined ? this.extendData.establishTime : '',
                businessScope: this.extendData.businessScope !== undefined ? this.extendData.businessScope : '',
                id: this.extendData.id !== undefined ? this.extendData.id : '',
                licenseCode: this.extendData.licenseCode !== undefined ? this.extendData.licenseCode : '',
                licensePicUrl: this.extendData.licensePicUrl !== undefined ? this.extendData.licensePicUrl : '',
                orgId: this.extendData.orgId !== undefined ? this.extendData.orgId : '',
                saleAmount: this.extendData.saleAmount !== undefined ? this.extendData.saleAmount : '',
                saleCount: this.extendData.saleCount !== undefined ? this.extendData.saleCount : '',
                staffNumber: this.extendData.staffNumber !== undefined ? this.extendData.staffNumber : '',
                pointProportion: this.extendData.pointProportion !== undefined ? this.extendData.pointProportion : ''
            }
        }
    })
</script>

<!-- 20170105 --></body>
</html>